
const relativeTime = require('dayjs/plugin/relativeTime')
const dayjs = require('dayjs')
/** 设置语言为中文 */
dayjs.locale('zh-cn')
dayjs.extend(relativeTime)
const formatTime = (date, pattern = 'YYYY-MM-DD HH:mm:ss') => {
  if (!isNull(date)) {
    const val = parseInt(date) * 1000
    return dayjs(val).format(pattern)
  } else {
    return '--'
  }
}

export const isNull = (value) => {
  if (!value) return true
  if (JSON.stringify(value) === '{}') return true
  if (JSON.stringify(value) === '[]') return true
}

export default (app) => {
  app.config.globalProperties.$filters = {
    formatTime
  }
}
